/**
 * 项目名称（软件名称）：忠旺机械物资管理系统(mms)
 * 研发设计单位：忠旺机械设备制造有限公司机械设计院智能控制设计科设计与研发。
 * 版权所有：忠旺机械设备制造有限公司
 * 注：本项目的一切技术专利，使用规范归解释权由忠旺机械设备制造有限公司所有。
 * 软件版本：Ver 1.0.0
 * 文件路径：com.zhongwang.mms.module.overview.service
 * 创建时间：2020年05月15日 10时00分
 **/
package com.zhongwang.mms.module.overview.service;

import com.zhongwang.mms.base.BaseService;
import com.zhongwang.mms.common.JsonResult;
import com.zhongwang.mms.module.overview.dao.OveIndexDao;
import com.zhongwang.mms.module.overview.model.OveIndexModel;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

/**
 * @ClassName： OveIndexService
 * @Description： 首页业务逻辑层
 * @Author： 徐一贺
 * @Date： 2020/5/15 10:00
 * @Version： V1.0
 **/
@Log4j2
@Service
@Primary
public class OveIndexService extends BaseService {
    @Autowired
    private OveIndexDao oveIndexDao;

    /**
     * @FunctionName: loadRawMaterialTopData
     * @Description: 加载首页原料库顶部数据
     * @DesignIdea: 加载首页原料库顶部数据
     * @Author: 徐一贺
     * @CreateDate: 2020/5/18 20:07
     * @Phone: 18241927380
     * @Param: [无参数
     * @Return: com.zhongwang.mms.common.JsonResult
     * @Throw: 无异常抛出, 已捕获处理异常, 已把异常记录在日志当中。
     * @Version: 1.0.0
     */
    public JsonResult loadRawMaterialTopData() {
        JsonResult result = new JsonResult();
        try {
            OveIndexModel data = new OveIndexModel();
            //钢材总重量
            data.setSteelTotalWeight(oveIndexDao.getRawMaterialSteelTotalWeight());
            data.setMatLiaoYangA(oveIndexDao.getRawMaterialSteelTotalWeightByWhiCode("辽阳库a"));
            data.setMatLiaoYangB(oveIndexDao.getRawMaterialSteelTotalWeightByWhiCode("辽阳库b"));
            data.setMatYingKou(oveIndexDao.getRawMaterialSteelTotalWeightByWhiCode("营口库"));
            //库存板材量
            data.setBoardTotalWeight(oveIndexDao.getRawMaterialBoardTotalWeight());
            data.setBoardLiaoYangA(oveIndexDao.getRawMaterialBoardTotalWeightByWhiCode("辽阳库a"));
            data.setBoardLiaoYangB(oveIndexDao.getRawMaterialBoardTotalWeightByWhiCode("辽阳库b"));
            data.setBoardYingKou(oveIndexDao.getRawMaterialBoardTotalWeightByWhiCode("营口库"));
            //库存型材量
            data.setProfileTotalWeight(oveIndexDao.getRawMaterialProfileTotalWeight());
            data.setProfileLiaoYangA(oveIndexDao.getRawMaterialProfileTotalWeightByWhiCode("辽阳库a"));
            data.setProfileLiaoYangB(oveIndexDao.getRawMaterialProfileTotalWeightByWhiCode("辽阳库b"));
            data.setProfileYingKou(oveIndexDao.getRawMaterialProfileTotalWeightByWhiCode("营口库"));
            //常用备件量
            data.setSparePartTotalWeight(oveIndexDao.getRawMaterialSparePartTotalWeight());
            data.setSparePartLiaoYangA(oveIndexDao.getRawMaterialSparePartTotalWeightByWhiCode("辽阳库a"));
            data.setSparePartLiaoYangB(oveIndexDao.getRawMaterialSparePartTotalWeightByWhiCode("辽阳库b"));
            data.setSparePartYingKou(oveIndexDao.getRawMaterialSparePartTotalWeightByWhiCode("营口库"));
            //项目总重量
            data.setProjectTotalWeight(oveIndexDao.getRawMaterialProjectTotalWeight());
            data.setProjectLiaoYangA(oveIndexDao.getRawMaterialProjectTotalWeightByWhiCode("辽阳库a"));
            data.setProjectLiaoYangB(oveIndexDao.getRawMaterialProjectTotalWeightByWhiCode("辽阳库b"));
            data.setProjectYingKou(oveIndexDao.getRawMaterialProjectTotalWeightByWhiCode("营口库"));
            result.setData(data);
            result.setType(JsonResult.ResultType.SUCCESS);
            result.setMsg("获取数据成功！");
        } catch (Exception e) {
            e.printStackTrace();
            log.error("首页加载原料库顶部数据异常，异常信息如下:\r\n" + e.getMessage());
            result.setType(JsonResult.ResultType.ERROR);
            result.setMsg("获取数据失败，请检查网络！");
        }
        return result;
    }

    /**
     * @FunctionName: loadRawMatDataByDate
     * @Description: 加载首页原料库中部数据
     * @DesignIdea: 加载首页原料库中部数据
     * @Author: 徐一贺
     * @CreateDate: 2020/5/19 9:04
     * @Phone: 18241927380
     * @Param: [无参数]
     * @Return: com.zhongwang.mms.common.JsonResult
     * @Throw: 无异常抛出
     * @Version: 1.0.0
     */
    public JsonResult loadRawMatDataByDate(OveIndexModel param) {
        JsonResult result= new JsonResult();
        try {
            OveIndexModel data = new OveIndexModel();
            /**原料库入库量（按照月份查询入库表中“签收单回货日期”满足当前月份的采购入库的有效数据对应的入库明细表中数据之和）*/
            data.setRawMatInTotalWeight(oveIndexDao.getRawMatInTotalWeight(param));
            /**原料库出库量（按照月份查询按照月份查询出库表中过账日期满足当前月份有效数据对应的出库明细表中数据之和）*/
            data.setRawMatOutTotalWeight(oveIndexDao.getRawMatOutTotalWeight(param));
            /**原料库消耗库存量（按照月份查询出库明细表中对应的在库状态是库存在库的所有有效数据之和，注意：库存划项目再出库不算库存消耗）*/
            data.setRawMatConsumeTotalWeight(oveIndexDao.getRawMatConsumeTotalWeight(param));
            /**原料库项目剩余产生量（按照月份查询项目划库存总量）*/
            data.setRawMatSurplusTotalWeight(oveIndexDao.getRawMatSurplusTotalWeight(param));
            /**原料库返库量（按照月份查询车间返库总量）*/
            data.setRawMatReturnTotalWeight(oveIndexDao.getRawMatReturnTotalWeight(param));
            result.setType(JsonResult.ResultType.SUCCESS);
            result.setMsg("获取数据成功！");
            result.setData(data);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
            result.setType(JsonResult.ResultType.ERROR);
            result.setMsg("获取数据失败！");
            result.setData(null);
        }
        return result;
    }
    /**
     *@FunctionName: loadRawMatApprovalPendingData
     *@Description: 加载首页原料库待审批数据
     *@DesignIdea: 加载首页原料库待审批数据
     *@Author: 徐一贺
     *@CreateDate: 2020/5/20 15:19
     *@Phone: 18241927380
     *@Param: []
     *@Return: com.zhongwang.mms.common.JsonResult 结果
     *@Throw: 无异常抛出
     *@Version: v 1.0.0
     */
    public JsonResult loadRawMatApprovalPendingData() {
        JsonResult result= new JsonResult();
        try {
            OveIndexModel data = new OveIndexModel();
            /**原料库未执行的串料申请*/
            data.setRawMatChangeCount(oveIndexDao.getRawMatChangeCount());
            /**原料库未执行的库存划项目标记*/
            data.setRawMatInvProCount(oveIndexDao.getRawMatInvProCount());
            /**原料库未执行的项目划库存标记*/
            data.setRawMatProInvCount(oveIndexDao.getRawMatProInvCount());
            /**原料库未执行的待审批数据（待审批调整申请）*/
            data.setRawMatApprovalPendingCount(oveIndexDao.getRawMatApprovalPendingCount());
            /**原料库未指定的使用库存计划*/
            data.setRawMatNotSpecifiedCount(oveIndexDao.getRawMatNotSpecifiedCount());
            /**还料提醒数目*/
            data.setRawReturnMatTipsCount(oveIndexDao.getRawReturnMatTipsCount().size());

            result.setType(JsonResult.ResultType.SUCCESS);
            result.setMsg("获取数据成功！");
            result.setData(data);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
            result.setType(JsonResult.ResultType.ERROR);
            result.setMsg("获取数据失败！");
            result.setData(null);
        }
        return result;
    }

    /**
     * @FunctionName: loadRawMaterialTopData
     * @Description: 加载首页外购件库顶部数据
     * @DesignIdea: 加载首页外购件库顶部数据
     * @Author: 徐一贺
     * @CreateDate: 2020/5/20 9:07
     * @Phone: 18241927380
     * @Param: [无参数]
     * @Return: com.zhongwang.mms.common.JsonResult
     * @Throw: 无异常抛出
     * @Version: 1.0.0
     */
    public JsonResult loadPurchaseTopData() {
        JsonResult result = new JsonResult();
        try {
            OveIndexModel data = new OveIndexModel();
            //外购件在库总金额（包括辽阳、营口机械备件库）
            data.setInventoryInStockTotalAmountByPurchaseAndHalf(oveIndexDao.getInventoryInStockTotalAmountByPurchaseAndHalf());
            //集团物资部外购件库库存金额
            data.setInventoryTotalAmountByPurchase(oveIndexDao.getInventoryTotalAmountByPurchase());
            //集团物资部外购件库项目在库金额
            data.setProjectInStockTotalAmountByPurchase(oveIndexDao.getProjectInStockTotalAmountByPurchase());
            //集团物资部外购件库库存在库金额
            data.setInventoryInStockTotalAmountByPurchase(oveIndexDao.getInventoryInStockTotalAmountByPurchase());
            //辽阳机械备件库在库金额
            data.setMecLiaoYang(oveIndexDao.getMecLiaoYang());
            //营口机械备件库在库金额
            data.setMecYingKou(oveIndexDao.getMecYingKou());
            //辽阳机械备件消耗品库在库金额
            data.setMecLiaoYangConsWarehouse(oveIndexDao.getMecLiaoYangConsWarehouse());
            //营口机械备件消耗品库在库金额
            data.setMecYingKouConsWarehouse(oveIndexDao.getMecYingKouConsWarehouse());
            //辽阳机械备件油漆库在库金额
            data.setMecLiaoYangPaintWarehouse(oveIndexDao.getMecLiaoYangPaintWarehouse());
            //营口机械备件油漆库在库金额
            data.setMecYingKouPaintWarehouse(oveIndexDao.getMecYingKouPaintWarehouse());
            result.setData(data);
            result.setType(JsonResult.ResultType.SUCCESS);
            result.setMsg("获取数据成功！");
        } catch (Exception e) {
            e.printStackTrace();
            log.error("首页加载外购件库顶部数据异常，异常信息如下:\r\n" + e.getMessage());
            result.setType(JsonResult.ResultType.ERROR);
            result.setMsg("获取数据失败，请检查网络！");
        }
        return result;
    }


    /**
     * @FunctionName: loadPurDataByDate
     * @Description: 加载首页外购件库中部数据
     * @DesignIdea: 加载首页外购件库中部数据
     * @Author: 徐一贺
     * @CreateDate: 2020/5/19 9:04
     * @Phone: 18241927380
     * @Param: [无参数]
     * @Return: com.zhongwang.mms.common.JsonResult
     * @Throw: 无异常抛出
     * @Version: 1.0.0
     */
    public JsonResult loadPurDataByDate(OveIndexModel param) {
        JsonResult result= new JsonResult();
        try {
            OveIndexModel data = new OveIndexModel();
            /**外购件库月入库金额*/
            data.setPurWarehousingAmountByMonth(oveIndexDao.getPurWarehousingAmountByMonth(param));
            /**外购件库月出库金额*/
            data.setPurOutWarehouseAmountByMonth(oveIndexDao.getPurOutWarehouseAmountByMonth(param));
            /**外购件库月库存划项目金额*/
            data.setPurInvProAmountByMonth(oveIndexDao.getPurInvProAmountByMonth(param));
            /**外购件库月串料金额*/
            data.setPurChangeAmountByMonth(oveIndexDao.getPurChangeAmountByMonth(param));
            /**外购件库月项目划库存金额*/
            data.setPurProInvAmountByMonth(oveIndexDao.getPurProInvAmountByMonth(param));
            result.setType(JsonResult.ResultType.SUCCESS);
            result.setMsg("获取数据成功！");
            result.setData(data);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
            result.setType(JsonResult.ResultType.ERROR);
            result.setMsg("获取数据失败！");
            result.setData(null);
        }
        return result;
    }
    /**
     * @FunctionName: loadPurApprovalPendingData
     * @Description: 加载首页外购件库待审批数据
     * @DesignIdea: 加载首页外购件库待审批数据
     * @Author: 徐一贺
     * @CreateDate: 2020/5/20 15:19
     * @Phone: 18241927380
     * @Param: []
     * @Return: com.zhongwang.mms.common.JsonResult 结果
     * @Throw: 无异常抛出
     * @Version: v 1.0.0
     */
    public JsonResult loadPurApprovalPendingData() {
        JsonResult result= new JsonResult();
        try {
            OveIndexModel data = new OveIndexModel();
            /**外购件库未执行的串料申请*/
            data.setPurChangeCount(oveIndexDao.getPurChangeCount());
            /**外购件库未执行的库存划项目标记*/
            data.setPurInvProCount(oveIndexDao.getPurInvProCount());
            /**外购件库未执行的项目划库存标记*/
            data.setPurProInvCount(oveIndexDao.getPurProInvCount());
            /**外购件库未执行的待审批数据（待审批调整申请）*/
            data.setPurApprovalPendingCount(oveIndexDao.getPurApprovalPendingCount());
            /**外购件库未指定的使用库存计划*/
            data.setPurNotSpecifiedCount(oveIndexDao.getPurNotSpecifiedCount());
            data.setPurNotSpecifiedCount2(oveIndexDao.getPurNotSpecifiedCount2());
            result.setType(JsonResult.ResultType.SUCCESS);
            result.setMsg("获取数据成功！");
            result.setData(data);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
            result.setType(JsonResult.ResultType.ERROR);
            result.setMsg("获取数据失败！");
            result.setData(null);
        }
        return result;
    }
    /**
     *@FunctionName: loadHalfTopData
     *@Description: 加载首页成品库顶部数据
     *@DesignIdea: 加载首页成品库顶部数据
     *@Author: 徐一贺
     *@CreateDate: 2020/5/20 16:51
     *@Phone: 18241927380
     *@Param: []
     *@Return: com.zhongwang.mms.common.JsonResult 结果
     *@Throw: 无异常抛出
     *@Version: v 1.0.0
     */
    public JsonResult loadHalfTopData() {
        JsonResult result = new JsonResult();
        try {
            OveIndexModel data = new OveIndexModel();

            //制作件在库数量
            data.setProductionPartInStockCountByHalf(oveIndexDao.getProductionPartInStockCountByHalf());
            //外协件库存金额
            data.setInventoryInStockTotalAmountByHalf(oveIndexDao.getInventoryInStockTotalAmountByHalf());
            //铝料库存金额
            data.setInventoryTotalAmountByHalf(oveIndexDao.getInventoryTotalAmountByHalf());
            //铝料库存重量（吨)
            data.setInventoryWeightByHalf(oveIndexDao.getInventoryWeightByHalf());
            //外协件库存数量
            data.setProjectInStockTotalAmountByHalf(oveIndexDao.getProjectInStockTotalAmountByHalf());
            result.setData(data);
            result.setType(JsonResult.ResultType.SUCCESS);
            result.setMsg("获取数据成功！");
        } catch (Exception e) {
            e.printStackTrace();
            log.error("首页加载原料库顶部数据异常，异常信息如下:\r\n" + e.getMessage());
            result.setType(JsonResult.ResultType.ERROR);
            result.setMsg("获取数据失败，请检查网络！");
        }
        return result;
    }
    /**
     *@FunctionName: loadHalfDataByDate
     *@Description: 加载首页成品库中部数据
     *@DesignIdea: 加载首页外成品库中部数据
     *@Author: 徐一贺
     *@CreateDate: 2020/5/21 8:10
     *@Phone: 18241927380
     *@Param: [无参数]
     *@Return: com.zhongwang.mms.common.JsonResult
     *@Throw: 无异常抛出
     *@Version: 1.0.0
     */
    public JsonResult loadHalfDataByDate(OveIndexModel param) {
        JsonResult result= new JsonResult();
        try {
            OveIndexModel data = new OveIndexModel();
            /**外协件月入库金额*/
            data.setPurAndOutsourcingWarehousingAmountByMonth(oveIndexDao.getPurAndOutsourcingWarehousingAmountByMonth(param));
            /**外协件月出库金额*/
            data.setPurAndOutsourcingOutWarehouseAmountByMonth(oveIndexDao.getPurAndOutsourcingOutWarehouseAmountByMonth(param));
            /**制作件月入库数量*/
            data.setProductionPartWarehousingCountByMonth(oveIndexDao.getProductionPartWarehousingCountByMonth(param));
            /**制作件月出库数量*/
            data.setProductionPartOutWarehouseCountByMonth(oveIndexDao.getProductionPartOutWarehouseCountByMonth(param));
            /**铝料月入库金额*/
            data.setAluminumWarehousingCountByMonth(oveIndexDao.getAluminumWarehousingCountByMonth(param));
            /**铝料月入库重量*/
            data.setAluminumWarehousingWeightCountByMonth(oveIndexDao.getAluminumWarehousingWeightCountByMonth(param));
            result.setType(JsonResult.ResultType.SUCCESS);
            result.setMsg("获取数据成功！");
            result.setData(data);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
            result.setType(JsonResult.ResultType.ERROR);
            result.setMsg("获取数据失败！");
            result.setData(null);
        }
        return result;
    }
    /**
     *@FunctionName: loadHalfApprovalPendingData
     *@Description: 加载首页成品库待审批数据
     *@DesignIdea: 加载首页外成品库待审批数据
     *@Author: 徐一贺
     *@CreateDate: 2020/5/21 9:49
     *@Phone: 18241927380
     * @Param: []
     * @Return: com.zhongwang.mms.common.JsonResult 结果
     * @Throw: 无异常抛出
     * @Version: v 1.0.0
     */
    public JsonResult loadHalfApprovalPendingData() {
        JsonResult result= new JsonResult();
        try {
            OveIndexModel data = new OveIndexModel();
            /**成品库未执行的串料标记*/
            data.setHalfChangeCount(oveIndexDao.getHalfChangeCount());
            /**成品库未执行的库存划项目标记*/
            data.setHalfInvProCount(oveIndexDao.getHalfInvProCount());
            /**成品库未执行的项目划库存标记*/
            data.setHalfProInvCount(oveIndexDao.getHalfProInvCount());
            /**成品库未执行的待审批数据（待审批调整申请）*/
            data.setHalfApprovalPendingCount(oveIndexDao.getHalfApprovalPendingCount());
            /**成品库未执行的调拨数据*/
            data.setHalfAllocationCount(oveIndexDao.getHalfAllocationCount());
            result.setType(JsonResult.ResultType.SUCCESS);
            result.setMsg("获取数据成功！");
            result.setData(data);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
            result.setType(JsonResult.ResultType.ERROR);
            result.setMsg("获取数据失败！");
            result.setData(null);
        }
        return result;
    }
}